package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.ProductSpec;
import com.spzx.product.domain.ProductUnit;
import com.spzx.product.service.IProductSpecService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.SortedSet;

@Tag(name = "商品规格接口管理")
@RestController
@RequestMapping("/productSpec")
public class ProductSpecController extends BaseController {
    @Autowired
    IProductSpecService productSpecService;

    @Operation(summary = "查询商品规格列表")
    @GetMapping("list")
    public TableDataInfo list (ProductSpec productSpec){
        startPage();
      List<ProductSpec>list= productSpecService.selectProductSpecList(productSpec);
        return getDataTable(list);
    }

    @Operation(summary = "获取商品规格详细信息")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id){
        return success(productSpecService.selectProductSpecById(id));
    }
    @Operation(summary = "新增规格")
    @PostMapping
    public AjaxResult addProductSpec(@RequestBody @Validated ProductSpec productSpec){
        return toAjax(productSpecService.save(productSpec));
    }
    @Operation(summary = "修改规格")
    @PutMapping
    public AjaxResult updateProductSpec(@RequestBody @Validated ProductSpec productSpec){
        return toAjax(productSpecService.updateById(productSpec));
    }
    @Operation(summary = "删除规格")
    @DeleteMapping("{ids}")
    public AjaxResult removeProductSpec(@PathVariable("ids")Long ids){
         return toAjax(productSpecService.removeBatchByIds(Arrays.asList(ids)));
    }
    @Operation(summary = "根据分类id 获取商品规格列表")
    @GetMapping("/productSpecList/{categoryId}")
    public AjaxResult getProductSpecById(@PathVariable("categoryId")Long categoryId){
        return AjaxResult.success(productSpecService.getProductSpecById(categoryId));
    }






}
